package com.finance.cooperate.common.exception;

import com.finance.cooperate.common.constant.CodeMsg;
import lombok.Data;

/**
 * @ClassName BaseException
 * @Description 异常基类，用来封装异常信息及初始化异常信息
 * @Author shen
 * @Date 2023/7/5 17:08
 * @Modify ...
 */
@Data
public class BaseException extends Exception{

    private static final long serialVersionUID = 1345251972041894292L;

    //错误码
    private String errorCode;
    //错误描述
    private String errorMsg;


    public BaseException(CodeMsg code) {
        this.errorCode = code.getCode();
        this.errorMsg = code.getMsg();
    }

    public BaseException(final String code, final String msg) {
        this.errorCode = code;
        this.errorMsg = msg;
    }

    public BaseException(Throwable e) {
        super(e);
    }

    /**
     * @Author shen
     * @Description 重写基类toString()方法
     * @Date 17:11 2023/7/5
     * @Param []
     * @return java.lang.String
     **/
    @Override
    public String toString() {
        StringBuffer sbf = new StringBuffer();
        sbf.append("错误码:[ ");
        sbf.append(this.getErrorCode());
        sbf.append(" ] ,错误信息:[ ");
        sbf.append(this.getErrorMsg());
        sbf.append("]");
        return sbf.toString();
    }

}
